#include "TextureManager.h"


TextureManager::TextureManager()
{
}


TextureManager::~TextureManager()
{
	clear();
}

bool TextureManager::loadTexture(const string &name){
	Texture *current = new Texture;

	bool success = current->loadFromFile("./img/"+name);

	if(!success){
		delete current;
		return false;
	}

	// If a shader with the same name already exists
	// we delete it and replace it.
	if(m_textures.find(name) != m_textures.end()){
		delete m_textures[name];
	}

	m_textures[name] = current;
}


Texture* TextureManager::getTexture(const string &name){
	return m_textures[name];
}


void TextureManager::clear(){
	map<string, Texture*>::iterator it;
	for(it = m_textures.begin(); it!=m_textures.end(); ++it){
		delete it->second;
	}

	m_textures.clear();
}